<!DOCTYPE html>
<html lang="cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组</title>
</head>

<body>

</body>

</html>
<script>
    // let arr1 = [11, 22, 33, 44];
    // let arr2 = new Array("aa", "bb", "cc", "dd");

    // document.write(arr1[1]);
    // document.write(arr2[3]);
    // document.write(arr2.length);

    // // 遍历输出数组的每一项
    // for (i = 0; i < arr1.length; i++) {
    //     document.write(arr1[i] + "<br>");

    // }

    // 需求：求数组 [2,6,1,7, 4] 里面所有元素的和以及平均值
    let arrNum = [2, 6, 1, 7, 4];
    let sum = 0;

    for (i = 0; i < arrNum.length; i++) {
        sum += arrNum[i];
    }
    document.write("和为：" + sum);
    document.write("平均值为：" + sum / arrNum.length);
</script>